/**
 * Project Name:spring-cloud-pilot
 * File Name:FileSnapshot.java
 * Package Name:org.spring.cloud.pilot.filewatch
 * Date:2019年10月18日上午10:17:45
 * Copyright (c) 2019, dengqian37@126.com All Rights Reserved.
 *
 */

package org.spring.cloud.pilot.filewatch;
/**
 * ClassName:FileSnapshot <br/>
 * Function: TODO ADD FUNCTION. <br/>
 * Reason: TODO ADD REASON. <br/>
 * Date: 2019年10月18日 上午10:17:45 <br/>
 * @author dengqian
 * @version
 * @since JDK 1.8
 * @see
 */
import java.io.File;

import org.springframework.util.Assert;

/**
 * A snapshot of a File at a given point in time.
 *
 * @author Phillip Webb
 */
class FileSnapshot {

    private final File file;

    private final boolean exists;

    private final long length;

    private final long lastModified;

    FileSnapshot(File file) {
        Assert.notNull(file, "File must not be null");
        Assert.isTrue(file.isFile() || !file.exists(), "File must not be a folder");
        this.file = file;
        this.exists = file.exists();
        this.length = file.length();
        this.lastModified = file.lastModified();
    }

    public File getFile() {
        return this.file;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (obj instanceof FileSnapshot) {
            FileSnapshot other = (FileSnapshot) obj;
            boolean equals = this.file.equals(other.file);
            equals = equals && this.exists == other.exists;
            equals = equals && this.length == other.length;
            equals = equals && this.lastModified == other.lastModified;
            return equals;
        }
        return super.equals(obj);
    }

    @Override
    public int hashCode() {
        int hashCode = this.file.hashCode();
        hashCode = 31 * hashCode + (this.exists ? 1231 : 1237);
        hashCode = 31 * hashCode + (int) (this.length ^ (this.length >>> 32));
        hashCode = 31 * hashCode + (int) (this.lastModified ^ (this.lastModified >>> 32));
        return hashCode;
    }

    @Override
    public String toString() {
        return this.file.toString();
    }
}